package com.sfx.算法专题.双指针.同向双指针.快慢指针;

/**
 * Created with IntelliJ IDEA.
 * Description:https://leetcode.cn/problems/find-the-duplicate-number/description/
 * 寻找重复数
 * User: sfx
 * Date: 2023-07-18
 * Time: 12:22
 */
public class Code_2_findDuplicate {

    static class Solution {
        public int findDuplicate(int[] nums) {
            int fast = 0;
            int slow = 0;
            fast = nums[nums[fast]];
            slow = nums[slow];
            while(fast!=slow) {
                slow = nums[slow];
                fast = nums[nums[fast]];
            }

            fast = 0;
            while(fast!=slow) {
                slow = nums[slow];
                fast = nums[fast];
            }
            return slow;
        }
    }
}
